{% extends 'base.html' %}
{% block title %}GLBLOG{% endblock %}

{% block head %}
    <link rel="stylesheet" href="{% static 'highlight/styles/github-dark.min.css' %}">
    <script src="{% static 'highlight/highlight.min.js' %}"></script>
{% endblock %}

{% block main %}
    <h1>{{ blog.title }}</h1>
    <hr>
    <div class="mt-2">
        <img src="{% static 'img/wen.png' %}" class="rounded-circle" style="height: 30px;width: 30px" alt="">
        <span class="ms-2">{{ blog.author.username }}</span>于{{ blog.pub_time|date:"Y年m月d日 h时i分" }}发布
    </div>
    <hr>
    <div class="py-2">
        {{ blog.content|safe }}
    </div>
    <hr>
    <div class="mt-2">
        <h3>评论({{ blog.comments.all|length }})</h3>
        <form action="{% url 'blog:blog_comment' %}" method="POST">
            {% csrf_token %}
            <input type="hidden" name="blog_id" value="{{ blog.id }}">
            <div class="mt-2 border border-primary">
                <input type="text" class="form-control" placeholder="评论..." name="content">
            </div>
            <div class="text-end mt-2">
                <button class="btn btn-primary">评论</button>
            </div>
        </form>
    </div>
    <div class="mt-2">
        <ul class="list-group list-group-flush">
            {% for comment in blog.comments.all %}
                <li class="list-group-item">
                    <div class="d-flex justify-content-between text-body-secondary">
                        <div class="user-info">
                            <img src="{% static 'img/wen.png' %}" class="rounded-circle" style="height: 40px;width: 40px" alt="">
                            <span class="ms-2">{{ comment.author.username }}</span>
                        </div>
                        <div class="create-time" style="line-height: 40px">
                            {{ comment.pub_time|date:"Y-m-d H:i" }}
                        </div>
                    </div>
                    <div class="mt-2">
                        {{ comment.content }}
                    </div>
                </li>
            {% endfor %}
        </ul>
    </div>
    <script>hljs.highlightAll();</script>
{% endblock %}